package BanyuanClub.Study.Day0317;

import java.nio.ByteBuffer;

public class TextIO {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(100);
        System.out.println("创建了一个100的字节缓冲区");
        System.out.println("p=" + buffer.position() + "l=" + buffer.limit() + "c=" + buffer.compact());

        buffer.put("哈哈哈哈".getBytes());
        System.out.println("放了四个字");
        System.out.println("p=" + buffer.position() + "l=" + buffer.limit() + "c=" + buffer.compact());

        buffer.flip();//翻转
        System.out.println("翻转");
        System.out.println("p=" + buffer.position() + "l=" + buffer.limit() + "c=" + buffer.compact());

        byte[] by = new byte[12];
        buffer.get(by);//取出12个字节
        System.out.println("取了12个字节");
        System.out.println("p=" + buffer.position() + "l=" + buffer.limit() + "c=" + buffer.compact());

        buffer.rewind();//倒带 b = 0;
        System.out.println("p=" + buffer.position() + "l=" + buffer.limit() + "c=" + buffer.compact());

        buffer.clear();//清空 b = 0,l = c;
        System.out.println("p=" + buffer.position() + "l=" + buffer.limit() + "c=" + buffer.compact());

    }
}
